package lab03.test01;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * Created by Administrator on 2017-11-10.
 */
public class Test {

    public static void main(String[] args) {


        /**
         * 读文件基本操作:读一个文件并打印文件内容。
         *
         *
         */

        String path = "D:\\hello.txt";

        //1. 字符流来读

        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(path));


            // 一次读一行字符
            String line = "";
            while ((line = reader.readLine()) != null) {

                System.out.println(line);
            }

            // 一次读一个字符
            int current;

            while ((current = reader.read()) != -1) {

                System.out.println((char) current);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


        //2. 字节流来读



    }
}
